*  FILE NAME: INVADJUS.PRG
*  BY: NURJADI PURNAMA
*  DATE: January 25, 1993
*  DESC:
*  CALLED BY:
*  DATA FILES:

set proc to sospro
SET CENT ON
SET PROC TO BOXPROC
set proc to ADDREPRO
STORE ' ' TO AEANAME,AEAADDR,AEACITY,AEACOUN,AEACURR,AEASTNM
STORE .F. TO AEAHEAL,AEADECI,AEASITE
do start
dr1='n:'
DR='N:'
F1='PATIENT'
TANG=DATE()
BULAC=CMONTH(DATE())

DO CASE
CASE BULAC='January'
   BULAL='December'
CASE BULAC='February'
   BULAL='January'
CASE BULAC='March'
   BULAL='February'
CASE BULAC='April'
   BULAL='March'
CASE BULAC='May'
   BULAL='April'
CASE BULAC='June'
   BULAL='May'
CASE BULAC='July'
   BULAL='June'
CASE BULAC='August'
   BULAL='July'
CASE BULAC='September'
   BULAL='August'
CASE BULAC='October'
   BULAL='September'
CASE BULAC='November'
   BULAL='October'
CASE BULAC='December'
   BULAL='November'
ENDCASE
SET COLO TO BG+/B
CLEAR
DO ADDRESSA
DO ADDRADJU

*PIL1=1
*DO BOX2 WITH 12,3,"INVOICE FOR MONTH ? :","&BULAC","&BULAL",'GR+','RB','GR+','R',PIL1,.F.,.T.
*DO CASE
*CASE LASTKEY()=27
*   RETURN
*CASE PIL1=1 .OR. PIL1=2
   DR1='N:'
   DR='N:'
   F2='ACTIVIT1'
   F21='ACTIVIT1'
   F3='REVENUE1'
   F31='REVINVO'
   F4='ACT_PRO1'
   F41='ACT_PRO1'
   F5='ACT_PHA1'
   F51='ACT_PHA1'
   F6='DOCT_FE1'
   F61='DOCTIN1'
   F7='CTLVOID'
   F71='CTLVOID'
*ENDCASE
*USE


PL1=0
DO WHILE .T.
   SET COLO TO BG+/B
   CLEAR
   DO ADDRESSA
   @  8,5 SAY 'VOID FOR PREVIOUS DAYS'   
   SET COLO TO BG+/B,W+/N
   @  9, 3 TO 19,68 DOUBLE
   SET COLO TO GR+*/B,W+/N
   @ 17, 10   SAY 'RUN I..  INDEXING FIRST, BEFORE YOU VOID THE INVOICE'
   SET COLO TO BG+/B,W+/N
   @ 10, 5 PROMPT "A .. VOID THIS INVOICE  "
   @ 12, 5 PROMPT "I .. INDEXING           "
   @ 14, 5 PROMPT "X .. EXIT PROGRAMME     "
   MENU TO PL1
   IF LAST()=27
      CLEAR
      RETURN
   ENDIF
   DO CASE
   CASE PL1=1
      KTR='VOID THIS INVOICE'
   CASE PL1=2
      KTR='INDEXING'
      ?KTR
      DO INVINDE
      LOOP
   CASE PL1=3
      RETURN
   ENDCASE
   SET COLO TO BG+*/B,W+/N
   @ 8,40-LEN(KTR)/2 SAY KTR
   SET COLO TO BG+/B,W+/N
   @  9, 3 CLEAR TO 23,68
   PATCOD=SPACE(6)
   INVOI=SPACE(5)
   INVDT=DATE()
   @ 10,7 SAY 'CMS INVOICE DATE. : ' GET INVDT
   @ 12,7 SAY 'CMS INVOICE NO.   : ' GET INVOI
   READ
   SELE 3
   SET EXCLU OFF
   USE &DR&F3 INDE &DR&F31
   SEEK DTOS(INVDT)+INVOI
   IF .not. found()
      CLOSE ALL
      LOOP
   ENDIF
   ACTCOD=PAT_FILCOD
   SET COLO TO BG+/B,W+/N
   NAMA=ALLTRIM(PAT_NAME)+' '+ALLTRIM(PAT_F_NAME)
   @ 10,45 SAY 'PATIENT NAME    : '+SUBS(NAMA,1,15)
   @ 12,45 SAY 'DATE OF INVOICE : '+DTOC(DATE_VISIT)
   @ 14,7 SAY 'PAYMENT MODE    : '+PAY_MODE
   @ 14,45 SAY 'INVOICE AMOUNT  : '+TRANS(TOTAL_FEE,'##,###,##9.99')
   @ 16,7 SAY 'CASH PAYMENT    : '+TRANS(TOTAL_CASH,'##,###,##9.99')
   @ 16,45 SAY 'CREDIT VOUCHER  : '+TRANS(TOTAL_CRED,'##,###,##9.99')
   @ 18,7 SAY 'HEALTHLINE      : '+TRANS(TOTAL_HL,'##,###,##9.99')	
   if substr(inv_stat,1,1)='V'
      @ 18,50 say 'Void by Cashier : '
      @ 18,69 say inv_stat
   else
      @ 18,50 say '                       '
      @ 18,69 say '     '
   endif
   TCAS=TOTAL_CASH
   TCRE=TOTAL_CRED
   @ 20, 45 SAY 'CONFIRM : Yes / No'
   @ 20,55 PROMPT 'Yes'
   @ 20,61 PROMPT 'No'
   MENU TO PIL1
   IF PIL1=2
      CLOSE ALL
      LOOP
   ENDIF

   OLDSELECT=SELECT()
   VOIDTRUE=.T.
   DO WHILE VOIDTRUE = .T.
      SELE 7
      USE &DR&F7 INDE &DR&F71
      SEEK DTOS(INVDT)+INVOI
      IF FOUND()
         @22, 7 SAY 'The Invoice already void, please take another number!'
         wait ''
         VOIDTRUE=.T.
         @22, 7 SAY '                                                     '
         RETURN
      ELSE
         SELE 7
	 APPEN BLANK
         IF REC_LOCK()
	    REPL DATE_VISIT WITH INVDT
	    REPL INV_NBER WITH INVOI
	 ENDIF   
         UNLOCK
         VOIDTRUE=.F.
      ENDIF   
      IF SUBSTR(INVOI,1,1)='A'
         @22, 7 SAY 'The Invoice already void, please take another number!'
         VOIDTRUE=.T.
      ENDIF
      
   ENDDO
   SELECT(OLDSELECT)
   DO CASE
   CASE PL1=1
      TPRIC  = 0
      THPRIC = 0
      TPPRIC = 0
      
      lHomvis=.F.
      
      SELE 4
      SET EXCLU OFF
      USE &DR&F4 INDE &DR&F41
      SEEK DTOS(INVDT)+INVOI
*** 
	    IF FOUND()
	       COPY TO C:\ACT_PRO_ FOR INV_NBER=INVOI.AND. INVDT=DATE_VISIT 
            ENDIF
***


? 'Please wait...'


      SEKALI=.T.
      SEEK INVOI
      DO WHILE INVOI=INV_NBER .AND. INVDT=DATE_VISIT .AND. .NOT. EOF()
         TPRIC  = TPRIC  + TOT_PRICE
         THPRIC = THPRIC + PROC_HL
         TPPRIC = TPPRIC + PROC_PAY
         CDOCT=DOC_CODE
         
         IF area_code+sub_areaco = 'G3'
      		lHomvis = .T.
	 ENDI

         IF CDOCT<>SPACE(3)
            SET COLO TO BG+/B,W+/N
            @ 22,38 CLEAR TO 22,45
            SELE 6
            SET EXCLU OFF
            USE &DR&F6 INDE &DR&F61
            SEEK DTOS(INVDT)+INVOI
*** 
	    IF FOUND()
	       IF SEKALI
  	          COPY TO C:\DOCT_FE_ FOR INV_NBER=INVOI .AND. INVDT=DATE_VISIT 
		  SEKALI=.F.
	       ENDIF
            ENDIF
***
            SEEK INVOI
            IF REC_LOCK()
               *DELE
            ENDIF
            UNLOCK
            SELE 4
         ENDIF
         IF REC_LOCK()
            *DELE
         ENDIF
         UNLOCK
         SKIP
      ENDDO

      SELE 5
      SET EXCLU OFF
      USE &DR&F5 INDE &DR&F51
      SEEK DTOS(INVDT)+INVOI
*** 
	    IF FOUND()
	       COPY TO C:\ACT_PHA_ FOR INV_NBER=INVOI .AND. INVDT=DATE_VISIT 
            ENDIF
***
      SEEK DTOS(INVDT)+INVOI
      DO WHILE INVOI=INV_NBER .AND. INVDT=DATE_VISIT .AND. .NOT. EOF()
         TPRIC  = TPRIC  + PHAR_PRICE
         THPRIC = THPRIC + PHAR_HL
         TPPRIC = TPPRIC + PHAR_PAY
         phar=phar_code
      	 phx=phar_x
         IF REC_LOCK()
            *DELE
         ENDIF
         UNLOCK
         
         oldselect=select()
	    do retqtydd
	 select(oldselect)	 

 	 SELE 5
         SKIP

      ENDDO
      SELE 1
      SET EXCLU OFF
      USE &DR1&F1 INDE &DR1&F1
      SEEK PATCOD

      SELE 2
      SET EXCLU OFF
      USE &DR&F2 INDE &DR&F21
      SEEK DTOS(INVDT)+INVOI
*** 
	    IF FOUND()
	       COPY TO C:ACTIVIT_ FOR INV_NBER=INVOI .AND. INVDT=DATE_VISIT 
            ENDIF
***
      SEEK DTOS(INVDT)+INVOI
      IF REC_LOCK()
         *DELE
      ENDIF
      UNLOCK

      SELE 3
      SET EXCLU OFF
      USE &DR&F3 INDE &DR&F31
      SEEK DTOS(INVDT)+INVOI
*** 
	    IF FOUND()
	       COPY TO C:REVENUE_ FOR INV_NBER=INVOI .AND. INVDT=DATE_VISIT 
            ENDIF
***
      SEEK DTOS(INVDT)+INVOI
      IF REC_LOCK()
         *DELE
      ENDIF
      UNLOCK
      OLDSELECT=SELECT()
      
***   MOVE DATA FROM ???????1 TO ???????V
***   DESCRIPTION IS "VACCT"
*******
*******

*   F7 = 'CTRPRN'                                                                                                                                                                                                                                          
*   SELE 6                                                                                                                                                                                                                                                 
*   SET EXCLU OFF                                                                                                                                                                                                                                          
 *  USE &DR&F7                                                                                                                                                                                                                                             
  * nCntr = CNTR+1
**
**
   *IF nCntr > 99999
    *    nCntr = 1
*   Endif
**
**
 *  IF Rec_LOCK()
  *    REPL CNTR WITH nCntr                                                                                                                                                                                                                                
   *ENDIF                                                                                                                                                                                                                                                  

*******
*******


      IF FILE("C:ACTIVIT_.DBF")
      SELE 24
      USE C:ACTIVIT_
      IF FIL_LOCK()
         REPL ALL INV_STAT   WITH "AV"
*	 REPL ALL TOTAL_FEE  WITH TOTAL_FEE*-1
*	 REPL ALL TOTAL_PROC WITH TOTAL_PROC*-1
*	 REPL ALL TOTAL_PHAR WITH TOTAL_PHAR*-1
	 *REPL ALL INV_NBER   WITH right('0000'+alltrim(str(int(nCntr))),5)
	 REPL ALL INV_NBER   WITH 'A'+substr(INV_NBER,2,5)
         REPL ALL DATE_VISIT WITH DATE()
      ENDIF	 
      UNLOCK
      ENDIF

      IF FILE("C:REVENUE_.DBF")
      SELE 24
      USE C:REVENUE_
      IF FIL_LOCK()
         REPL ALL INV_STAT   WITH "AV"
*	 REPL ALL TOTAL_FEE  WITH TOTAL_FEE*-1
*	 REPL ALL TOTAL_PROC WITH TOTAL_PROC*-1
*	 REPL ALL TOTAL_PHAR WITH TOTAL_PHAR*-1
*	 REPL ALL TOTAL_PAY  WITH TOTAL_PAY*-1
*	 REPL ALL TOTAL_CASH WITH TOTAL_CASH*-1
*	 REPL ALL TOTAL_CRED WITH TOTAL_CRED*-1
*	 REPL ALL TOTAL_HL   WITH TOTAL_HL*-1
*	 REPL ALL OTHE_AMNT  WITH OTHE_AMNT*-1
*	 REPL ALL VAT_AMOUNT WITH VAT_AMOUNT*-1
*	 REPL ALL SRV_AMOUNT WITH SRV_AMOUNT*-1
*         REPL ALL CHAN_AMNT  WITH CHAN_AMNT*-1
	 *REPL ALL INV_NBER   WITH right('0000'+alltrim(str(int(nCntr))),5)
	 REPL ALL INV_NBER   WITH 'A'+substr(INV_NBER,2,5)
         REPL ALL DATE_VISIT WITH DATE()
      ENDIF
      UNLOCK	 
      ENDIF
      
      IF FILE("C:ACT_PRO_.DBF")
      SELE 24
      USE C:ACT_PRO_
      IF FIL_LOCK()
         REPL ALL INV_STAT   WITH "AV"
*	 REPL ALL TOT_PRICE  WITH TOT_PRICE*-1
*	 REPL ALL PROC_PAY   WITH PROC_PAY*-1
*	 REPL ALL PROC_HL    WITH PROC_HL*-1
*	 REPL ALL PUB_PRICE  WITH PUB_PRICE*-1
	 *REPL ALL INV_NBER   WITH right('0000'+alltrim(str(int(nCntr))),5)
	 REPL ALL INV_NBER   WITH 'A'+substr(INV_NBER,2,5)
         REPL ALL DATE_VISIT WITH DATE()
      ENDIF
      UNLOCK
      ENDIF
      	 
      IF FILE("C:ACT_PHA_.DBF")
      SELE 24
      USE C:ACT_PHA_
      IF FIL_LOCK()
         REPL ALL INV_STAT    WITH "AV"
*	 REPL ALL PHAR_PRICE  WITH PHAR_PRICE*-1
*	 REPL ALL PHAR_PAY    WITH PHAR_PAY*-1
*	 REPL ALL PHAR_HL     WITH PHAR_HL*-1
*	 REPL ALL SALE_PRICE  WITH SALE_PRICE*-1
*	 REPL ALL PHAR_SALE   WITH PHAR_SALE*-1
	 *REPL ALL INV_NBER   WITH right('0000'+alltrim(str(int(nCntr))),5)
	 REPL ALL INV_NBER   WITH 'A'+substr(INV_NBER,2,5)
         REPL ALL DATE_VISIT  WITH DATE()
      ENDIF
      UNLOCK
      ENDIF
      	 
      IF FILE("C:DOCT_FE_.DBF")
      SELE 24
      USE C:DOCT_FE_
      IF FIL_LOCK()
         REPL ALL INV_STAT   WITH "AV"
*	 REPL ALL DOC_FEE    WITH DOC_FEE*-1
*	 REPL ALL PROC_PAY   WITH PROC_PAY*-1
 *	 REPL ALL PUB_PRICE  WITH PUB_PRICE*-1
*	 REPL ALL TOT_PRICE  WITH TOT_PRICE*-1
	 *REPL ALL INV_NBER   WITH right('0000'+alltrim(str(int(nCntr))),5)
	 REPL ALL INV_NBER   WITH 'A'+substr(INV_NBER,2,5)
         REPL ALL DATE_VISIT WITH DATE()
      ENDIF
      UNLOCK
      ENDIF


CLOS ALL
USE

      IF FILE("C:ACTIVIT_.DBF")
         F24="ACTIVITV"
         SELE 24
	 SET EXCLU OFF
         USE &DR&F24         

	 F25="C:ACTIVIT_.DBF"
         APPEN FROM &F25

      ENDIF
      
      IF FILE("C:REVENUE_.DBF")
         F24="REVENUEV"
         SELE 24
	 SET EXCLU OFF
         USE &DR&F24            
         APPEN FROM C:REVENUE_.DBF
      ENDIF

      IF FILE("C:ACT_PRO_.DBF")
         F24="ACT_PROV"
         SELE 24
	 SET EXCLU OFF
         USE &DR&F24
         APPEN FROM C:ACT_PRO_.DBF
      ENDIF            

      IF FILE("C:ACT_PHA_.DBF")
         F24="ACT_PHAV"
         SELE 24
	 SET EXCLU OFF
         USE &DR&F24            
         APPEN FROM C:ACT_PHA_.DBF
      ENDIF
      
      IF FILE("C:DOCT_FE_.DBF")
         F24="DOCT_FEV"
         SELE 24
	 SET EXCLU OFF
         USE &DR&F24            
         APPEN FROM C:DOCT_FE_.DBF
      ENDIF

***   DELETE FILE TEMPORARY
      
      DELE FILE C:ACTIVIT_.dbf
      DELE FILE C:REVENUE_.dbf
      DELE FILE C:ACT_PRO_.dbf
      DELE FILE C:ACT_PHA_.dbf
      DELE FILE C:DOCT_FE_.dbf
***
      SELECT(OLDSELECT)

   ENDCASE
ENDDO
